package com.hiyee.api.config;

import com.hiyee.pojo.auth.CustomerTokenInfo;

/**
 * 线程本地持有者：存储当前请求线程的登录用户
 *
 * @author WangBin
 */
public class ThreadLocalHolder {

    private final static ThreadLocal<CustomerTokenInfo> ThreadLocalHolder = new ThreadLocal<>();

    /**
     * 重写ThreadLocal的三个方法：set、get、remove
     */
    public static void set(CustomerTokenInfo customer) {
        ThreadLocalHolder.set(customer);
    }

    public static CustomerTokenInfo get() {
        return ThreadLocalHolder.get();
    }

    public static void remove() {
        ThreadLocalHolder.remove();
    }

    /**
     * 获取登录用户的常用信息：id、姓名
     */
    public static Long getId() {
        return ThreadLocalHolder.get().getCustomerId();
    }

    public static String getName() {
        return ThreadLocalHolder.get().getNickname();
    }
}